package com.mjf.day1

import org.apache.flink.api.scala._

/**
 * 从 Flink 1.12 开始，DataSet API 已被软弃用。
 */
object WordCountFromBatch2 {
  def main(args: Array[String]): Unit = {

    val env: ExecutionEnvironment = ExecutionEnvironment.getExecutionEnvironment
    env.setParallelism(1)

    val input: DataSet[String] = env.fromElements(
      "hello world",
      "hello world",
      "hello world"
    )

    val result: AggregateDataSet[(String, Int)] = input
      .flatMap(_.split(" "))
      .map((_, 1))
      .groupBy(0)
      .sum(1)

    result.print()

  }
}
